﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using UploadingControl.SilverlightService;

namespace UploadingControl
{
    public partial class UploadWithPageNumber : UserControl
    {
        public string FileFormat { get; set; }
        public string Title { get; set; }
        public UploadWithPageNumber()
        {
            InitializeComponent();
            fileUpload1.Initialize("/documents/News", "news-" + FileFormat + "-" + this.Title + "-", "Please insert Page order");

        }


        private void txtOrederNo_TextChanged(object sender, TextChangedEventArgs e)
        {
            int orderNo = 0;
            try
            {
                orderNo = Convert.ToInt32(txtOrederNo.Text);
                fileUpload1.isUploadFile = true;
                fileUpload1.Initialize("/documents/News", "news-" + FileFormat + "-" + this.Title + "-" + orderNo.ToString(), "News");
            }
            catch
            {
                orderNo = 0;
                fileUpload1.isUploadFile = false;
                fileUpload1.Initialize("/documents/News", "news-" + FileFormat + "-" + this.Title + "-" + orderNo.ToString(), "Please insert Page order");
            }
        }

        public void Reset()
        {
            fileUpload1.Initialize("/documents/News", "news-" + FileFormat + "-" + this.Title + "-", "Please insert Page order");
            fileUpload1.CompleteUploadedURL = "";
            txtOrederNo.Text = "";
        }

        public bool CanUploadFile
        {
            get
            {
                if (fileUpload1.CompleteUploadedURL != null && fileUpload1.CompleteUploadedURL != "")
                    return true;
                else
                    return false;
            }
        }

        public int OrderNo
        {
            get
            {
                return Convert.ToInt32(txtOrederNo.Text);
            }
        }
        public string Description
        {
            get
            {
                return txtDescription.Text;
            }
        }
        public string FileName
        {
            get
            {
                return fileUpload1.CompleteUploadedURL;
            }
        }
    }
}
